﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace CoffeePotServer
{
    public class Client_Response
    {
        #region Attributes
        private Socket _client;
        private NetworkStream _networkStream;
        private const int BufferSize = 1024;
        #endregion

        #region Constructor
        public Client_Response(NetworkStream networkStream, Socket client)
        {
            _networkStream = networkStream;
            _client = client;
        }
        #endregion

        #region Methods
        public String ReadLine()
        {
            if (_networkStream.CanRead)
            {
                String strMessage = "";
                byte[] byteBuffer = new byte[1024];
                int intNumBytes;
                do
                {
                    intNumBytes = _networkStream.Read(byteBuffer, 0, byteBuffer.Length);
                    strMessage += ByteArrayToString(byteBuffer, intNumBytes);
                } while (intNumBytes != 0  && (ByteArrayToString(byteBuffer, intNumBytes) != "\r\n"));
                return strMessage;
            }
            return null;
        }

        private String ByteArrayToString(byte[] bytArrToConvert, int intLength)
        {
            return Encoding.ASCII.GetString(bytArrToConvert, 0, intLength);
        }
        #endregion
    }
}
